home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Admin2.aspx.cs678 < prev    next >
Text File  |  2008-02-23  |  18KB  |  435 lines

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Net;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.HtmlControls;
  11. using GBPVR.Public;
  12. using GBPVRSchedule;
  13. using gbweb.classes;
  14.  
  15. namespace gbweb
  16. {
  17.     /// <summary>
  18.     /// Summary description for Admin.
  19.     /// </summary>
  20.     public partial class Admin2 : Page
  21.     {
  22.         protected HtmlInputText mimeType;
  23.     
  24.         private Settings guideParams;
  25.  
  26.         protected void Page_Load(object sender, EventArgs e)
  27.         {
  28.             //Code to prevent Guest users from accessing the Admin page directly by URL
  29.             if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
  30.             {
  31.                 string hostAddress = string.Empty;
  32.                 string Url =
  33.                     Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
  34.                                                    Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
  35.  
  36.  
  37.                 string redirectUrl = Url.ToLower().Replace("admin2.aspx", "guide2.aspx");
  38.                 Logger.Info(" ");
  39.                 Logger.Info(" ");
  40.                 Logger.Info("Guest user trying to access the admin page......");
  41.                 Logger.Info("Pulling User IP Info...");
  42.                 if (Request.UserHostAddress.Substring(0, 1) == ":")
  43.                 {
  44.                     Logger.Info("IP V6 Detected");
  45.                     hostAddress = GetIP4Address();
  46.                     Logger.Info("IP6 Address: " + Request.UserHostAddress);
  47.                     Logger.Info("IP4 Address: " + hostAddress);
  48.                     Logger.Info(" ");
  49.                 }
  50.                 else
  51.                 {
  52.                     Logger.Info("IP V4 Detected");
  53.                     hostAddress = Request.UserHostAddress;
  54.                     Logger.Info("IP4 Address: " + hostAddress);
  55.                     Logger.Info(" ");
  56.                 }
  57.                 Logger.Info("Redirecting user to the guide");
  58.                 Logger.Info(" ");
  59.                 Logger.Info(" ");
  60.                 Response.Redirect(redirectUrl, true);
  61.             }
  62.  
  63.             Session["GuideStartTime"] = null;
  64.             if (User.Identity.Name.Length == 0)
  65.                 {
  66.                     FormsAuthentication.SignOut();
  67.                     Response.Redirect("Login.aspx?ReturnUrl=" + Request.ApplicationPath + "/Admin2.aspx");
  68.                 }
  69.  
  70.             guideParams = Global.Settings;
  71.             //Set the header tab of the Admin to active
  72.             NAV_CONFIG.Attributes.Add("class", "currentTab");
  73.             NAV_GUIDE.Visible = guideParams.showTVGuide;
  74.             NAV_RECORDINGS.Visible = guideParams.showManage;
  75.             NAV_SEARCH.Visible = guideParams.showSearch;
  76.             NAV_VIDEO.Visible = guideParams.showVideoLib;
  77.             NAV_MUSIC.Visible = guideParams.showMusicLib;
  78.             NAV_PHOTO.Visible = guideParams.showPhotoLib;
  79.             NAV_STATS.Visible = guideParams.showStats;
  80.  
  81.             VLCCommon VLC = new VLCCommon(1);
  82.             VLCCommon VLC2 = new VLCCommon(2);
  83.             
  84.             if (!IsPostBack) 
  85.             {
  86.                 //Set the Day/date/time display on the header
  87.                 viewDate.InnerText = DateTime.Now.ToLongDateString().Trim();
  88.                 serverTime.InnerText = "Server Time: " + DateTime.Now.ToLongTimeString().Trim();
  89.                 
  90.                 string[] themes = Directory.GetDirectories(Server.MapPath(Request.ApplicationPath + "/themes2/"));
  91.                 //Create an array to hold the theme names so we can easily sort it later
  92.                 ArrayList themenames = new ArrayList();
  93.                 foreach (string theme in themes)
  94.                 {
  95.                     //Load each theme that is found in the themes directory to the array of names
  96.                     if (File.Exists(Path.Combine(theme, "styles.css")))
  97.                     {
  98.                         themenames.Add(Path.GetFileName(theme));
  99.                     }
  100.                 }
  101.                 //set the first theme in the list to Default
  102.                 //dropdownThemes.Items.Add("Default");
  103.                 //Sort the loaded themes into alphabetical order
  104.                 themenames.Sort();
  105.                 //Add the sorted themnames to the dropdown list
  106.                 foreach (string s in themenames)
  107.                 {
  108.                     dropdownThemes.Items.Add(s);
  109.                 }
  110.             
  111.                 HttpCookie cookie = Request.Cookies["minuteSpan"];
  112.                 txtMinuteSpan.Value = cookie != null ? cookie.Value : "120";
  113.                 
  114.                 cookie = Request.Cookies["minuteInterval"];
  115.                 txtMinuteInterval.Value = cookie != null ? cookie.Value : "30";
  116.                 
  117.                 cookie = Request.Cookies["minuteSlice"];
  118.                 txtMinuteSlice.Value = cookie != null ? cookie.Value : "1";
  119.                 
  120.                 cookie = Request.Cookies["TimelineRepeat"];
  121.                 txtTimelineRepeat.Value = cookie != null ? cookie.Value : "10";
  122.  
  123.                 guideStartTime.Text = guideParams.guideStartTime;
  124.                 DateTime now = DateTime.Now;
  125.                 DateTime then = now.AddMinutes(Convert.ToDouble(guideParams.reminder));
  126.                 TimeSpan span = then - now;
  127.                 txtReminderDays.Value = span.Days.ToString();
  128.                 txtReminderHours.Value = span.Hours.ToString();
  129.                 txtReminderMinutes.Value = span.Minutes.ToString();
  130.  
  131.                 dropdownRecordingQuality.SelectedValue    = guideParams.recordingQuality.ToString();
  132.                 
  133.                 string themeName = Convert.ToString(Session["theme"]);
  134.                 if (themeName != null && themeName != "")
  135.                 {
  136.                     int themeIdx = themeName.IndexOf("/");
  137.                     if (themeIdx > 0)
  138.                     {
  139.                     themeName = themeName.Substring(themeIdx + 1, themeName.Length - (themeIdx + 1));
  140.                     dropdownThemes.SelectedValue = themeName;
  141.                     }
  142.                     else
  143.                     {
  144.                         dropdownThemes.SelectedValue  = "Prototype";
  145.                     }
  146.                 }
  147.                 else
  148.                 {
  149.                     dropdownThemes.SelectedValue = "Prototype";
  150.                 }
  151.  
  152.                 displayTabs.Items[0].Selected           = guideParams.showTVGuide;
  153.                 displayTabs.Items[1].Selected           = guideParams.showManage;
  154.                 displayTabs.Items[2].Selected           = guideParams.showSearch;
  155.                 displayTabs.Items[3].Selected           = guideParams.showVideoLib;
  156.                 displayTabs.Items[4].Selected           = guideParams.showMusicLib;
  157.                 displayTabs.Items[5].Selected           = guideParams.showPhotoLib;
  158.                 displayTabs.Items[6].Selected           = guideParams.showStats;
  159.                 showDescription.Checked                    = guideParams.showDescription;
  160.                 showDescription.Checked                    = guideParams.showDescription;
  161.                 showSubtitle.Checked                    = guideParams.showSubtitle;
  162.                 showGenre.SelectedValue                    = guideParams.showGenre;
  163.                 showRating.Checked                        = guideParams.showRating;
  164.                 showNew.Checked                            = guideParams.showNew;
  165.                 showIMDB.Checked                        = guideParams.showIMDB;
  166.                 showNetflix.Checked                        = guideParams.showNetflix;
  167.                 showTVCom.Checked                       = guideParams.showTVCom;
  168.                 showWiki.Checked                        = guideParams.showWiki;
  169.                 showCredits.Checked                        = guideParams.showCredits;
  170.                 showAirDate.Checked                        = guideParams.showAirDate;
  171.                 showStarRating.Checked                    = guideParams.showStarRating;
  172.                 showHD.Checked                          = guideParams.showHD;
  173.                 playlistExtension.Value                 = guideParams.playlistExtension;
  174.                 cookie                                  = Request.Cookies["useChannelIcons"];
  175.                 UseChannelIcons.SelectedValue           = cookie != null ? cookie.Value : "chnlText";
  176.                 autoShowSearch.SelectedValue            = guideParams.autoShowSearch.ToString();
  177.                 autoRecordSearch.SelectedValue          = guideParams.autoShowRecord.ToString();
  178.                 autoSearchEPGDays.Value                 = guideParams.autoSearchDays.ToString();
  179.                 
  180.                 
  181.                 cookie                                  = Request.Cookies["channelIconHeight"];
  182.                 txtChnlIconH.Value                      = cookie != null ? cookie.Value : "";
  183.                 cookie                                  = Request.Cookies["channelIconWidth"];
  184.                 txtChnlIconW.Value                      = cookie != null ? cookie.Value : "";
  185.                 
  186.                 txtAutologinList.Text                    = guideParams.autologinNetworks;
  187.  
  188.                 guestUser.Value                         = guideParams.GuestUser;
  189.                 guestPassword.Value                     = guideParams.GuestPassword;
  190.  
  191.                 //Web Streamer Variables
  192.                 
  193.                 streamPlayer.Text                       = guideParams.strmPlayer;
  194.                 externalPlayer.Checked                  = guideParams.strmExternal;
  195.                 streamPlayer2.Text                      = guideParams.strmPlayer2;
  196.                 externalPlayer2.Checked                 = guideParams.strmExternal2;
  197.  
  198.                 //Web Streamer VLC Common Class
  199.                 strmVLCLoc.Text                         = VLC.getVLCLoc();
  200.                 strmVLCLoc2.Text                        = VLC2.getVLCLoc();
  201.  
  202.                 spanExtendedEWA.Visible = ExtendedEWA.Initialize();
  203.                 
  204.             }
  205.             
  206.         }
  207.  
  208.         #region Web Form Designer generated code
  209.         override protected void OnInit(EventArgs e)
  210.         {
  211.             //
  212.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  213.             //
  214.             InitializeComponent();
  215.             base.OnInit(e);
  216.         }
  217.         
  218.         /// <summary>
  219.         /// Required method for Designer support - do not modify
  220.         /// the contents of this method with the code editor.
  221.         /// </summary>
  222.         private void InitializeComponent()
  223.         {
  224.  
  225.         }
  226.         #endregion
  227.  
  228.         protected void forceSearch_Click(object sender, EventArgs e)
  229.         {
  230.             SavedSearchUtils searchUtil = new SavedSearchUtils();
  231.             searchUtil.autoSearch(searchUtil.loadAutoSearches());
  232.         }
  233.  
  234.         protected void Kill_All_Reminders_Click(object sender, EventArgs e)
  235.         {
  236.             Schedule scheduleHelper = Global.Schedule;
  237.             ArrayList reminders = scheduleHelper.GetReminderList();
  238.             foreach (Programme programme in reminders)
  239.             {
  240.                 scheduleHelper.RemoveReminder(programme);
  241.             }
  242.         }
  243.  
  244.         protected void hlSubmit_Click(object sender, EventArgs e)
  245.         {
  246.             HttpCookie cookie = new HttpCookie("minuteSpan", txtMinuteSpan.Value);
  247.             cookie.Expires = DateTime.Now.AddYears(1);
  248.             Response.Cookies.Add(cookie);
  249.             
  250.             cookie = new HttpCookie("minuteInterval", txtMinuteInterval.Value);
  251.             cookie.Expires = DateTime.Now.AddYears(1);
  252.             Response.Cookies.Add(cookie);
  253.             
  254.             cookie = new HttpCookie("minuteSlice", txtMinuteSlice.Value);
  255.             cookie.Expires = DateTime.Now.AddYears(1);
  256.             Response.Cookies.Add(cookie);
  257.             
  258.             cookie = new HttpCookie("TimelineRepeat", txtTimelineRepeat.Value);
  259.             cookie.Expires = DateTime.Now.AddYears(1);
  260.             Response.Cookies.Add(cookie);
  261.  
  262.             guideParams.guideStartTime = guideStartTime.Text;
  263.  
  264.             double minutes = 0;
  265.  
  266.             try
  267.             {
  268.                 minutes = ((Convert.ToDouble(txtReminderDays.Value) * 24) * 60);  
  269.             }
  270.             catch
  271.             {
  272.                 minutes = 0;
  273.                 txtReminderDays.Value = "0";
  274.             }
  275.             
  276.             try
  277.             {
  278.                 minutes += (Convert.ToDouble(txtReminderHours.Value) * 60); 
  279.             }
  280.             catch
  281.             {
  282.                 minutes += 0;
  283.                 txtReminderHours.Value = "0";
  284.             }
  285.             
  286.             try
  287.             {
  288.                 minutes += Convert.ToDouble(txtReminderMinutes.Value); 
  289.             }
  290.             catch
  291.             {
  292.                 minutes += 0;
  293.                 txtReminderMinutes.Value = "0";
  294.             }
  295.  
  296.             guideParams.reminder = minutes.ToString();
  297.  
  298.             guideParams.recordingQuality = dropdownRecordingQuality.SelectedValue;
  299.             
  300.             //Save the selected theme to the cookie for future use as well as the Session for current use
  301.             cookie = new HttpCookie("theme", dropdownThemes.SelectedValue);
  302.             cookie.Expires = DateTime.Now.AddYears(1);
  303.             Response.Cookies.Add(cookie);
  304.  
  305.             Session["theme"] = "themes2/" + dropdownThemes.SelectedValue; 
  306.  
  307.             guideParams.showTVGuide         = displayTabs.Items[0].Selected;
  308.             guideParams.showManage          = displayTabs.Items[1].Selected;
  309.             guideParams.showSearch          = displayTabs.Items[2].Selected;
  310.             guideParams.showVideoLib        = displayTabs.Items[3].Selected;
  311.             guideParams.showMusicLib        = displayTabs.Items[4].Selected;
  312.             guideParams.showPhotoLib        = displayTabs.Items[5].Selected;
  313.             guideParams.showStats           = displayTabs.Items[6].Selected;
  314.             guideParams.showDescription        = showDescription.Checked;
  315.             guideParams.showSubtitle        = showSubtitle.Checked;
  316.             guideParams.showGenre            = showGenre.SelectedValue;
  317.             guideParams.showRating            = showRating.Checked;
  318.             guideParams.showNew              = showNew.Checked;
  319.             guideParams.showIMDB            = showIMDB.Checked;
  320.             guideParams.showNetflix            = showNetflix.Checked;
  321.             guideParams.showTVCom           = showTVCom.Checked;
  322.             guideParams.showWiki            = showWiki.Checked;
  323.             guideParams.showCredits            = showCredits.Checked;
  324.             guideParams.showAirDate            = showAirDate.Checked;
  325.             guideParams.showStarRating        = showStarRating.Checked;
  326.             guideParams.showHD              = showHD.Checked;
  327.             guideParams.autoShowSearch      = Convert.ToBoolean(autoShowSearch.SelectedValue);
  328.             guideParams.autoShowRecord      = Convert.ToBoolean(autoRecordSearch.SelectedValue);
  329.             guideParams.autoSearchDays      = Convert.ToDouble(autoSearchEPGDays.Value);
  330.  
  331.             cookie = new HttpCookie("showTVGuide", displayTabs.Items[0].Selected.ToString());
  332.             cookie.Expires = DateTime.Now.AddYears(1);
  333.             Response.Cookies.Add(cookie);
  334.  
  335.             cookie = new HttpCookie("useChannelIcons", UseChannelIcons.SelectedValue);
  336.             cookie.Expires = DateTime.Now.AddYears(1);
  337.             Response.Cookies.Add(cookie);
  338.             
  339.             guideParams.playlistExtension    = playlistExtension.Value;
  340.             
  341.             cookie = new HttpCookie("channelIconHeight", txtChnlIconH.Value);
  342.             cookie.Expires = DateTime.Now.AddYears(1);
  343.             Response.Cookies.Add(cookie);
  344.             
  345.             cookie = new HttpCookie("channelIconWidth", txtChnlIconW.Value);
  346.             cookie.Expires = DateTime.Now.AddYears(1);
  347.             Response.Cookies.Add(cookie);
  348.             
  349.             guideParams.autologinNetworks    = txtAutologinList.Text;
  350.  
  351.             guideParams.GuestUser           = guestUser.Value;
  352.             guideParams.GuestPassword       = getMd5Hash(guestPassword.Value);
  353.  
  354.             //Web Streamer
  355.             guideParams.strmPlayer          = streamPlayer.Text;
  356.             guideParams.strmExternal        = externalPlayer.Checked;
  357.             guideParams.strmVLCLoc          = strmVLCLoc.Text;
  358.             guideParams.strmPlayer2         = streamPlayer2.Text;
  359.             guideParams.strmExternal2       = externalPlayer2.Checked;
  360.             guideParams.strmVLCLoc2         = strmVLCLoc2.Text;
  361.  
  362.             Global.Settings.Save();
  363.  
  364.             string[] invalidAutologinNetworks = guideParams.ParseAutologinNetworks();
  365.             if (invalidAutologinNetworks.Length > 0)
  366.             {
  367.                 lblAutologinWarning.Text = "WARNING: Invalid ranges: " + string.Join(",", invalidAutologinNetworks);
  368.             } 
  369.             else 
  370.             {
  371.                 lblAutologinWarning.Text = string.Empty;
  372.             }
  373.             Page.RegisterStartupScript("startupScript", "<script language=JavaScript>reload();</script>");
  374.         }
  375.  
  376.         static string getMd5Hash(string input)
  377.         {
  378.             // Create a new instance of the MD5CryptoServiceProvider object.
  379.             MD5 md5Hasher = MD5.Create();
  380.  
  381.             // Convert the input string to a byte array and compute the hash.
  382.             byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
  383.  
  384.             // Create a new Stringbuilder to collect the bytes
  385.             // and create a string.
  386.             StringBuilder sBuilder = new StringBuilder();
  387.  
  388.             // Loop through each byte of the hashed data 
  389.             // and format each one as a hexadecimal string.
  390.             for (int i = 0; i < data.Length; i++)
  391.             {
  392.                 sBuilder.Append(data[i].ToString("x2"));
  393.             }
  394.  
  395.             // Return the hexadecimal string.
  396.             return sBuilder.ToString();
  397.         }
  398.  
  399.         protected void sizeDefault_Click(object sender, EventArgs e)
  400.         {
  401.             txtChnlIconH.Value = string.Empty;
  402.             txtChnlIconW.Value = string.Empty;
  403.         }
  404.  
  405.         protected void hlAutologinInternal_Click(object sender, EventArgs e)
  406.         {
  407.             txtAutologinList.Text = "127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16";
  408.         }
  409.  
  410.         protected void hlAutologinNone_Click(object sender, EventArgs e)
  411.         {
  412.             txtAutologinList.Text = "none";
  413.         }
  414.         protected void txtPort_TextChanged(object sender, EventArgs e)
  415.         {
  416.  
  417.         }
  418.  
  419.         public string GetIP4Address()
  420.         {
  421.             string strIP4Address = String.Empty;
  422.  
  423.             foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
  424.             {
  425.                 if (objIP.AddressFamily.ToString() == "InterNetwork")
  426.                 {
  427.                     strIP4Address = objIP.ToString();
  428.                     break;
  429.                 }
  430.             }
  431.             return strIP4Address;
  432.         }
  433.     }
  434. }
  435.